package com.yjj.demo.spring.redis.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class InitService implements ApplicationListener {

    private Logger logger = LoggerFactory.getLogger(InitService.class);

    private String key = "test:a";

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        //rightPush();
    }

    public void rightPush() {
        logger.info("redis list init");
        stringRedisTemplate.opsForList().rightPushAll(key, "8", "9", "10", "3", "2", "1");
        stringRedisTemplate.opsForList().rightPush(key, "5");
    }
}
